#include <pthread.h>
#include <string>

typedef void(*callBack)();

static int num = 0;

class Thread
{
public:
    Thread(callBack cb)
        :cb_(cb), name_(""), isRunning_(false), tid_(0), timestamp_(0)
    {}
    static void *Routine(void *args)
    {
        Thread *td = static_cast<Thread*>(args);
        td->Entry();
        return nullptr;     //写上返回值，严谨
    }
    void Start()
    {
        name_ = "thread-" + std::to_string(num++);
        isRunning_ = true;
        timestamp_ = time(nullptr);
        pthread_create(&tid_, nullptr, Routine, this);
    }
    void Entry()
    {
        cb_();
    }
    void Join()
    {
        pthread_join(tid_, nullptr);
        isRunning_ = false;     //线程结束后，记得将其置为false
    }
    std::string GetName()
    {
        return name_;
    }
    bool IsRunning()
    {
        return isRunning_;
    }
    int64_t GetTimestamp()
    {
        return timestamp_;
    }

private:
    callBack cb_;
    std::string name_;
    bool isRunning_;
    pthread_t tid_;
    uint64_t timestamp_;        //可以定义为无符号的，因为不可能为负数
};